﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Windows.Ria;
using SoftSource.Ria;
using SoftSource.Timecard.Web.Data;

namespace SoftSource.Timecard.Entry.Model
{
    public sealed partial class DefaultModel : IModelQueries
    {
        public IObservable<Unit> LoadData()
        {
            return Observable.CreateWithDisposable<Unit>(observer =>
            {
                return this.PreLoadQuery.Subscribe(unit =>
                {
                    this.SetResources();
                    observer.OnNext(unit);
                    observer.OnCompleted();
                });
            });
        }

        public IObservable<IEnumerable<EntryLog>> GetEntriesForCurrentUserByDateRange(DateTime start, DateTime end)
        {
            return this.entries.Query(this.entries.GetEntriesForCurrentUserByDateRangeQuery(start, end), LoadBehavior.RefreshCurrent);
        }

        public IObservable<IEnumerable<EntryLog>> GetFilteredEntries(
            int? projectID,
            int? userID,
            DateTime? startDate,
            DateTime? endDate)
        {
            return this.entries.Query(this.entries.GetFilteredEntryLogsQuery(
                projectID,
                userID,
                startDate,
                endDate));
        }
    }
}
